Release 10.1A: OpenEdge Development:
Programming Interfaces
Defining additional input/output streams
When you start a procedure, Progress automatically provides that procedure with input and output streams. As described in the previous sections, the default source for the input stream is the terminal and the default destination for the output stream is also the terminal. You saw how to use the
INPUTFROMandOUTPUTTOstatements to redirect these input and output streams.You might find that having just one input stream and one output stream is not enough for particular procedures. That is, you might want to get input from more than one source at the same time or send output to more than one destination at the same time.
Suppose you want to produce a report of the items you have in inventory and you want to send the report to a file. You already know how to use the
OUTPUTTOstatement to redirect the output stream to a file. Suppose that you also want to produce an “exceptions” report at the same time. Any item where the allocated amount is greater than the on-hand amount is an exception. Figure 5–8 illustrates this scenario.Figure 5–8: Multiple output streams scenario
![]()
For items that are exceptions, the procedure needs to send output to a second location. That means you need two different output streams.
You use the
DEFINESTREAMstatement to define additional streams for a procedure to get input from more than one source simultaneously and send output to more than one destination simultaneously. Streams you name can be operating system files, printers, the terminal, or other non-terminal devices.The procedure
i-dfstr.puses the two report scenarios shown in Figure 5–8.
The numbers to the left of the procedure correspond to the following step-by-step descriptions:
- The
SETstatement prompts you for the filenames you want to use for the Item Inventory Report and for the Item Exception Report. It stores your answers in thefnrandfnevariables, respectively.- The
OUTPUTSTREAMstatements open two output streams, namedrptand exceptions. These streams were defined at the start of the procedure with theDEFINESTREAMstatement.The
rptand exceptions streams are directed to the files whose names you supplied:VALUE(fnr)andVALUE(fne). This means that output can now be sent to either or both of those files.- The
DISPLAYstatement displays the text Item Inventory Report. But instead of displaying that text on the terminal, it displays it to therptstream. The file you named for the Item Inventory Report contains the text Item Inventory Report.- This
DISPLAYstatement also displays text but it uses the exceptions stream. The file you named for the Item Exception Report contains the text Item Exception Report.- The
FOREACHblock reads a single item record on each iteration of the block.- If the allocated amount of an item is larger than the on-hand amount of that item:
- The
DISPLAYstatement displays item data to the exceptions stream. After thisDISPLAYstatement finishes, the file you named for the Item Exception Report contains item data for a single item.- The excount counter variable, defined at the start of the procedure, is incremented by 1. The value of this variable is displayed at the end of the procedure so that you know the total number of exception items in inventory.
- The exception logical variable, defined at the start of the procedure, is set to
TRUE.- The
DISPLAYstatement displays some item data to therptstream. After this statement finishes, the file you named for the Item Inventory Report contains item data for a single item.- If the item is an exception, determined by the value in the exception logical variable, the
DISPLAYstatement displays the string “See Exception Report” to therptstream. That way you know, when looking at the Item Inventory Report, which items are exceptions.- The
DISPLAYstatement displays the value of the excount variable to the exceptions stream. The value of this variable is the total number of exception items.- This
DISPLAYstatement displays the value of the excount variable to therptstream. Although theDISPLAYstatement does not explicitly say what is being displayed, it does name the same frame,exc, as is used to display excount in the previousDISPLAYstatement. That means that theexcframe already contains the excount value. Thus, all this secondDISPLAYstatement has to do is name the same frame.- The
OUTPUTSTREAMCLOSEstatements close therptand exception streams, redirecting all further output to the default output destination.
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |